package com.web.test.dao;

import com.web.test.bean.Question;
import com.web.test.utils.Constants;
import com.web.test.utils.JDBCUtil;

import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * Created by Administrator on 2017/9/23.
 */
public class AnswerDao {

    public boolean find(Question question, String stuOption)
            throws ClassNotFoundException, SQLException, IOException {

        String sql;
        if (question.getType() == Constants.WRITE_Q) {

            sql = "SELECT * FROM ANSWER a WHERE QUESTION_NO='" + question.getNo() + "' AND a.CORRECT_OPTION LIKE '" + stuOption + "'";

        } else {

            sql = "SELECT * FROM ANSWER a WHERE QUESTION_NO='" + question.getNo() + "' AND a.CORRECT_OPTION ='" + stuOption + "'";
        }
        Connection connection = JDBCUtil.getConnection();
        Statement statement = connection.createStatement();
        ResultSet rSet = statement.executeQuery(sql);

        while (rSet.next()) {
            JDBCUtil.close(connection, statement, rSet);
            return true;
        }
        return false;

    }


}
